package com.stock;

import com.kevin.core.util.StringUtils;
import com.kevin.dao.StockDetailDao;
import com.kevin.entity.StockDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class StockDetailService {
	final static String api="http://xueqiu.com/v4/stock/quote.json?code={}&_="+new Date().getTime();
	
	@Autowired
	StockDetailDao dao;

	public StockDetail query(String symbol){
		String url=StringUtils.fromat(api, symbol);
		String json=Client.doGet(url);
		Parser parser=new StockDetailParser();
		return (StockDetail) parser.parse(json);
	}

	public void save(String symbol){
		StockDetail stockDetail = this.query(symbol);
		System.out.println(stockDetail);
		dao.save(stockDetail);
	}

	public void deleteAll(){
		dao.deleteAll();
	}

}
